package com.example.bawolf.jms.queue;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * AppProducer
 *
 * @author zhougf
 * @date 2020/03/06
 */
public class AppProducer {
    public static void main(String[] args) throws JMSException {
        String activeMqUrl = "tcp://49.234.184.233:61616";
        String queueName = "queue01";
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(activeMqUrl);
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();
        Session connectionSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = connectionSession.createQueue(queueName);
        MessageProducer producer = connectionSession.createProducer(queue);
        for(int i = 0; i < 3; i++){
            TextMessage textMessage = connectionSession.createTextMessage("消息" + i);
            producer.send(textMessage);
        }
        producer.close();
        connectionSession.close();
        connection.close();
        System.out.println("消息已发送");
    }
}
